<template>
  <div class="public_height100 p20 pub_bgColorFFF">
    <div class="table_content">
      <div class="flb">
        <div class="crumbs flex_start">
          <span class="crumbs_active" @click="goPage('/layout/company?activeIndex=4-7')">公司列表</span>
          <img src="@/assets/img/customer/crumbs_next.png" alt="返回" class="pub_imgSize16 ml8" />
          <span class="ml8 ">员工信息</span>
        </div>
        <div class="cGR lh24 pt fs16" @click="goPage('/layout/ordinaryAdmin?activeIndex=6-1')">去账户列表添加员工信息</div>
      </div>
      <!-- ====== 表格上方的筛选条件 end ======-->
      <el-table ref="multipleTable" size="mini" :data="tableData" tooltip-effect="dark" border :height="`${536 * $f}px`" class="wp100 mt12" @selection-change="handleSelectionChange">
        <el-table-column label="姓名" show-overflow-tooltip prop="" align="center">
          <template slot-scope="{ row }">
            {{ row.companySaleName || '管理员' }}
          </template>
        </el-table-column>
        <el-table-column label="手机号" show-overflow-tooltip prop="companySalePhone" align="center" />
        <template slot="empty">
          <PageEmptyData />
        </template>
      </el-table>
      <div ref="pubPageinationRef" class="pub_pageination flex_center mt18">
        <el-pagination background layout="total,prev, pager, next" :total="tableData.length" :page-size="tableData.length"> </el-pagination>
      </div>
    </div>
    <!-- 删除提示 -->
    <deleteDialog :multiple-selection="multipleSelection" :visible="deleteDialogVisible" @close="closeDialog" @submit="confirmDelete" />
  </div>
</template>
<script>
import tableFun from '@/mixin/tableFun.js';
export default {
  mixins: [tableFun],
  data() {
    return {
      params: {
        commonSearch: ''
      },
      addParams: {
        id: '',
        companySaleName: '',
        companySalePhone: ''
      }
    };
  },
  created() {
    this.params.companyId = this.$route.query.companyId;
    this.getDataList();
  },
  mounted() {},
  methods: {
    closeDialog() {
      this.deleteDialogVisible = false;
    },
    //获取表格数据
    async getDataList() {
      let { data } = await this.$api.get(this.$url.companySaleAllByCompanyId, this.params);
      this.tableData = data || [];
    },
    //确认删除
    async confirmDelete() {
      let res = await this.$api.post(this.$url.companySaleDelete, { id: this.selectedRow.id });
      this.closeDialog();
      if (res.code === 200) {
        this.$message.success('删除成功');
        this.getDataList();
      } else {
        this.$message.success('删除失败');
      }
    },
    //确认添加
    async confirmAdd() {
      let { companySaleName, companySalePhone, id } = this.addParams;
      if (!companySaleName) {
        return this.$message.warning('请输入公司');
      }
      let reg = /^1(3[0-9]|4[5-9]|5[0-35-9]|6[567]()|7[0-8]|8[0-9]|9[0-9])\d{8}$/;
      if (!reg.test(companySalePhone)) {
        return this.$message.warning('请输入正确手机号');
      }
      let url = id ? this.$url.companySaleUpdate : this.$url.companySaleAdd;
      this.addParams.companyId = this.$route.query.companyId;
      let res = await this.$api.post(url, ...this.addParams);
      if (res.code === 200) {
        this.closeDialog();
        this.getDataList();
        this.$message.success(id ? '更新成功' : '新增成功');
      }
    },
    //跳转到员工信息页面
    goPage(path) {
      this.$router.push({ path });
    }
  }
};
</script>
<style lang="less" scoped>
.table_content {
  height: calc(100% - 49px);
}
</style>
